using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.LBS.Scene;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Windows;
using System.Windows.Media.Imaging;
namespace MicroMsg.Plugin.LBS
{
	public class LBS : PluginBase, FMsgChange
	{
		private const string TAG = "LBS";
		public const string PluginKey = "Plugin LBS";
		public const long PluginID = 32773L;
		public const string PluginName = "LBS";
		public const int PluginVersion = 256;
		public const string bNotFirstInLbsKey = "bNotFirstInLbs";
		private static LBS mInstance;
		public LbsService sceneLbsService;
		public override string mTitle
		{
			get
			{
				return strings.FF_Entry_PeopleNearBy;
			}
		}
		public override string mFFEntryTitle
		{
			get
			{
				return strings.FF_Entry_PeopleNearBy;
			}
		}
		public override BitmapSource mIcon
		{
			get
			{
				if (MMTheme.IsCoolBlackTheme())
				{
					return ImageCacheMgr.loadFromRes("Resource/Img/Lbs/plugin_setting_cool.png");
				}
				return ImageCacheMgr.loadFromRes("Resource/Img/Lbs/plugin_setting_normal.png");
			}
		}
		public override BitmapSource mIconHD
		{
			get
			{
				return ImageCacheMgr.loadFromRes("Resource/Img/Lbs/plugin_setting_HD.png");
			}
		}
		public override BitmapSource mIconInList
		{
			get
			{
				return this.mIcon;
			}
		}
		public override string mDescription
		{
			get
			{
				return strings.Plugin_LBS_Info;
			}
		}
		public override string mAuthor
		{
			get
			{
				return "tencent";
			}
		}
		public LBS()
		{
			this.mKey = "Plugin LBS";
			this.mID = 32773L;
			this.mName = "LBS";
			this.mVersion = 256;
			this.mIndexInTab = MainTabIndex.FindFriendTab;
			this.mIndexInGroup = 0;
			this.mIndexInPosition = 3;
			this.mProtocolPluginFlag = EPluginFlag.MM_LBS_UNISTALL;
			this.mDefaultInstalled = true;
			LBS.mInstance = this;
			base.mIconInFFEntry = ImageCacheMgr.loadFromRes(MMTheme.GetInstance().lbsPeople_main);
			base.mIconFlagInFFEntry = ImageCacheMgr.loadFromRes(MMTheme.GetInstance().lbsPeople_footprint);
		}
		public override PluginSettingBaseCtrl GetPluginSettingCtrl()
		{
			return new LbsPluginSetCtrl();
		}
		private void onBtnClickLbs(object sender, RoutedEventArgs e)
		{
			this.execute(4, null);
		}
		public static LBS getInstance()
		{
			return LBS.mInstance;
		}
		public override void onRegisterResult(RetConst retConst_0, int code)
		{
			Log.smethod_4("LBS", string.Concat(new object[]
			{
				"on register result , ret = ",
				retConst_0,
				", code = ",
				code
			}));
		}
		public override bool onInitialize()
		{
			Log.smethod_4("LBS", "initialize. ");
			this.sceneLbsService = new LbsService();
			this.refreshUnReadCnt();
			FMsgMgr.addObserver(this);
			return true;
		}
		public override bool onUnInitialize()
		{
			Log.smethod_4("LBS", "onUnInitialize");
			base.onUnInitialize();
			FMsgMgr.removeObserver(this);
			return true;
		}
		public override bool onInstalled(InstallMode mode)
		{
			Log.smethod_4("LBS", "on inistalled. ");
			return true;
		}
		public override bool onUninstalled(InstallMode mode)
		{
			Log.smethod_4("LBS", "on uninstalled. ");
			this.sceneLbsService.doCleanPosition();
			FMsgMgr.CleanByType(FMsgType.const_0);
			return true;
		}
		public override bool onParseChatMsg(ChatMsg chatMsg)
		{
			return false;
		}
		public override bool isShowFlagImage()
		{
			return !NetSceneLbs.isLbsLocationOutdate();
		}
		public override object execute(int entryType, object args)
		{
			Log.smethod_4("LBS", "plugin execute,   entrytype =" + entryType);
			if (entryType == 1)
			{
				return null;
			}
			if (entryType == 2)
			{
				return null;
			}
			if (entryType == 3)
			{
				this.entryLbsFromFriendTab();
				return null;
			}
			if (entryType == 4)
			{
				this.entryLbsFromFriendTab();
				return null;
			}
			return null;
		}
		private void entryLbsFromFriendTab()
		{
			if (!ConfigMgr.getBool("bNotFirstInLbs", false))
			{
				object[] pData = new object[]
				{
					default(object),
					"/Source/Plugin/Lbs/UI/LbsGuidPage.xaml"
				};
				LocationServiceTipPage.GotoThisPage(pData);
				return;
			}
			if (AccountMgr.IsAcountInfoCompleted())
			{
				object[] pData2;
				if (FMsgMgr.getNewMsgNum(FMsgType.const_0) > 0)
				{
					pData2 = new object[]
					{
						new object[]
						{
							LbsPeopleListComeFrom.COME_FROM_DIRECTLY
						},
						"/Source/Plugin/Lbs/UI/LbsChoosePage.xaml"
					};
				}
				else
				{
					pData2 = new object[]
					{
						new object[]
						{
							LbsPeopleListComeFrom.COME_FROM_DIRECTLY
						},
						"/Source/Plugin/Lbs/UI/LbsPeopleList.xaml"
					};
				}
				LocationServiceTipPage.GotoThisPage(pData2);
				return;
			}
			object[] pData3 = new object[]
			{
				new object[]
				{
					strings.COM_SeeAround,
					"/Source/Plugin/Lbs/UI/LbsPeopleList.xaml"
				},
				"/Source/Plugin/Lbs/UI/LbsInputUserInfo.xaml"
			};
			LocationServiceTipPage.GotoThisPage(pData3);
		}
		public void refreshFootPrintFlag()
		{
			if (this.mFFEntryCallBack != null)
			{
				this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_UpdateFootPrint, null);
			}
		}
		public override void SetFFEntryCallBack(StandardUITaskDlg FFEntryCallBack)
		{
			this.mFFEntryCallBack = FFEntryCallBack;
			this.refreshFootPrintFlag();
			this.refreshUnReadCnt();
		}
		private void refreshUnReadCnt()
		{
			int newMsgNum = FMsgMgr.getNewMsgNum(FMsgType.const_0);
			this.setUnreadCnt(newMsgNum);
		}
		private void setUnreadCnt(int nCnt)
		{
			if (this.mFFEntryCallBack != null)
			{
				try
				{
					this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_Cnt, nCnt);
				}
				catch
				{
				}
			}
		}
		public void onFMsgAdd(ChatMsg chatMsg_0, FMsgType type)
		{
			this.refreshUnreadCntIfNeed(type);
		}
		public void onFMsgDel(ChatMsg chatMsg_0, FMsgType type)
		{
			this.refreshUnreadCntIfNeed(type);
		}
		public void onFMsgNewNumChange(FMsgType type)
		{
			this.refreshUnreadCntIfNeed(type);
		}
		private void refreshUnreadCntIfNeed(FMsgType type)
		{
			if (type != FMsgType.const_0)
			{
				return;
			}
			this.refreshUnReadCnt();
		}
	}
}
